//
//  TSInviteViewController.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/11/6.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSInviteViewController: TSBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationController?.delegate = self;
        
        creatCustomNavi()
        configViews()
    }

    @objc func inviteAction() {
        
        navigationController?.pushViewController(TSInvationViewController(), animated: true)
    }

    deinit {
        self.navigationController?.delegate = nil
    }
}

extension TSInviteViewController {
    
    func configViews() {
        
//        let container = UIView.init()
//        container.backgroundColor = WHITE_COLOR
//        self.view.addSubview(container)
//        container.snp.makeConstraints { (make) in
//            make.left.right.centerY.equalToSuperview()
//        }
        
        let bgImg = UIImageView.init(image: UIImage(named: "invite_bg"))
        bgImg.isUserInteractionEnabled = true
        self.view.addSubview(bgImg)
        bgImg.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().inset(T_TABBARHEIGHT)
            make.top.equalTo(T_NAVBARHEIGHT)
//            make.centerX.top.equalToSuperview()
//            make.size.equalTo(CGSize(width: 317*T_ScreenScale(), height: 364*T_ScreenScale()))
        }
        
        let inviteBtn = UIButton.init(type: .system)
        inviteBtn.setTitle("立即邀请", for: .normal)
        inviteBtn.setTitleColor(UIColor.clear, for: .normal)
        inviteBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .medium)
//        inviteBtn.backgroundColor = BASE_PURPLE_COLOR
        inviteBtn.addTarget(self, action: #selector(inviteAction), for: .touchUpInside)
        bgImg.addSubview(inviteBtn)
        inviteBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-170)
            make.size.equalTo(CGSize(width: SCREEN_WIDTH*0.61, height: 150))
        }
    }
    
    func creatCustomNavi() {
        
        let customStatus = UIView.init()
        customStatus.backgroundColor = BASE_RED_COLOR
        self.view.addSubview(customStatus)
        customStatus.snp.makeConstraints { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(STATUSBAR_HEIGHT)
        }
        
        let customNavi = UIView.init()
        customNavi.backgroundColor = BASE_RED_COLOR
        self.view.addSubview(customNavi)
        customNavi.snp.makeConstraints { (make) in
            make.left.right.equalTo(customStatus)
            make.top.equalTo(customStatus.snp.bottom)
            make.height.equalTo(NAVIGATIONBAR_HEIGHT)
        }
        
        let titleLabel = UILabel.init()
        titleLabel.text = "邀请好友"
        titleLabel.textColor = WHITE_COLOR
        titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
        customNavi.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
    }
}

// MARK: - UINavigationControllerDelegate
extension TSInviteViewController : UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        let isShowHomePage = viewController.isKind(of: TSInviteViewController.self)
        self.navigationController?.setNavigationBarHidden(isShowHomePage, animated: false)
    }
}

